package cn.fxl.basic.service.impl;

import cn.fxl.basic.mapper.BasicMapper;
import cn.fxl.basic.pageList.GmResult;
import cn.fxl.basic.query.BasicQuery;
import cn.fxl.basic.service.IBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.mail.MessagingException;
import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BasicServiceImpl<T> implements IBasicService<T> {
    @Autowired
    private BasicMapper<T>  basicMapper;
    @Override
    public List<T> getAll() {
        return basicMapper.getAll();
    }

    @Override
    public T getOne(Long id) {
        return (T) basicMapper.getOne(id);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        basicMapper.remove(id);
    }

    @Override
    @Transactional
    public void save(T t) throws MessagingException {
        basicMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        basicMapper.update(t);
    }



    @Override
    public GmResult<T> Pagequery(BasicQuery basicQuery) {
        Integer totals = basicMapper.totals(basicQuery);
        if(totals==null||totals==0){
            return new GmResult<>();
        }
        List<T> data = basicMapper.queryData(basicQuery);
        GmResult<T> tGmResult = new GmResult<>(totals, data);
        return tGmResult;
    }

    @Override
    @Transactional
    public void pathchdel(Long[] a) {
        basicMapper.pathchdel(a);
    }
}
